home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / String Extractor⁄Localization / Scanner / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-19  |  2.9 KB  |  137 lines  |  [TEXT/KAHL]

  1. /*
  2.  main.c
  3. */
  4.  
  5. #include "FolderUtils.h"
  6. #include "Extract.h"
  7. #include "Error.h"
  8. #include "string.h"
  9.  
  10.  
  11. Handle foom = NULL ;
  12. short idBase = 128 ;
  13.  
  14.  
  15. static void
  16. InitMac ( long stackSpace ) {
  17.     if ( stackSpace ) {
  18.         SetApplLimit ( CurStackBase - stackSpace ) ;
  19.     }
  20.     MaxApplZone ( ) ;
  21.  
  22.     InitGraf ( & qd . thePort ) ;
  23.     InitFonts ( ) ;
  24.     InitWindows ( ) ;
  25.     InitMenus ( ) ;
  26.     TEInit ( ) ;
  27.     InitDialogs ( NULL ) ;
  28. }
  29.  
  30.  
  31. static void
  32. DoExtract ( short vRefNum , long parID , unsigned char * fileName ) {
  33.  
  34. short refNum ;
  35. Handle text ;
  36. long size ;
  37.  
  38.     Error ( HOpenDF ( vRefNum , parID , fileName , fsRdWrPerm , & refNum ) ) ;
  39.     Error ( GetEOF ( refNum , & size ) ) ;
  40.     text = NewHandle ( size ) ;
  41.     if ( ! text ) {
  42.         Error ( MemError ( ) ) ;
  43.     }
  44.     HLock ( text ) ;
  45.     Error ( FSRead ( refNum , & size , * text ) ) ;
  46.     HUnlock ( text ) ;
  47.  
  48.     PtrAndHand ( "\r/* " , foom , 4 ) ;
  49.     PtrAndHand ( & fileName [ 1 ] , foom , fileName [ 0 ] ) ;
  50.     PtrAndHand ( " */\r" , foom , 4 ) ;
  51.     Error ( MemError ( ) ) ;
  52.  
  53.     Extract ( text , foom , idBase , 1 ) ;
  54.     idBase ++ ;
  55.  
  56.     Error ( SetFPos ( refNum , fsFromStart , 0L ) ) ;
  57.     size = GetHandleSize ( text ) ;
  58.     Error ( SetEOF ( refNum , size ) ) ;
  59.     HLock ( text ) ;
  60.     Error ( FSWrite ( refNum , & size , * text ) ) ;
  61.     Error ( FSClose ( refNum ) ) ;
  62.     DisposeHandle ( text ) ;
  63. }
  64.  
  65.  
  66. static void
  67. ScanFolder ( short vRefNum , long parID ) {
  68.  
  69. CInfoPBRec rec ;
  70. Str63 fileName ;
  71. int ix ;
  72. char * foom ;
  73. short err ;
  74.  
  75.     memset ( & rec , 0 , sizeof ( rec ) ) ;
  76.     for ( ix = 1 ; ix > 0 ; ix ++ ) {
  77.         rec . hFileInfo . ioVRefNum = vRefNum ;
  78.         rec . hFileInfo . ioDirID = parID ;
  79.         rec . hFileInfo . ioNamePtr = fileName ;
  80.         rec . hFileInfo . ioFDirIndex = ix ;
  81.         if ( err = PBGetCatInfoSync ( & rec ) ) {
  82.             if ( err == fnfErr ) {
  83.                 break ;
  84.             } else {
  85.                 Error ( err ) ;
  86.             }
  87.         }
  88.         foom = ( char * ) fileName ;
  89.         foom += fileName [ 0 ] ;
  90.         foom [ 1 ] = 0 ;
  91.         foom -= 1 ;
  92.         if ( ! strcmp ( foom , ".c" ) || ! strcmp ( --foom , ".cp" ) ||
  93.             ! strcmp ( --foom , ".cpp" ) ) {
  94.             DoExtract ( vRefNum , parID , fileName ) ;
  95.         }
  96.     }
  97. }
  98.  
  99.  
  100. void
  101. main ( void ) {
  102.  
  103. short vRefNum = 0 ;
  104. long parID = 0 ;
  105. StandardFileReply reply ;
  106. short refNum ;
  107. long size ;
  108. FSSpec fss ;
  109.  
  110.     InitMac ( 0 ) ;
  111.  
  112.     StandardPutFile ( "\PSave Rez source:" , "\PLiterals.r" , & reply ) ;
  113.     if ( ! reply . sfGood ) {
  114.         ExitToShell ( ) ;
  115.     }
  116.     Error ( FSpCreate ( & reply . sfFile , 'KAHL' , 'TEXT' , reply . sfScript ) ) ;
  117.     foom = NewHandle ( 0L ) ;
  118.     if ( ! foom ) {
  119.         Error ( MemError ( ) ) ;
  120.     }
  121.     PtrAndHand ( "#include \"Types.r\"\r\r" , foom , 20 ) ;
  122.  
  123.     if ( GetAFolderFSS ( & fss , "\PSelect a folder containing C source" ) ) {
  124.         vRefNum = fss . vRefNum ;
  125.         Error ( GetFolderID ( & fss , & parID ) ) ;
  126.         ScanFolder ( vRefNum , parID ) ;
  127.     }
  128.     Error ( FSpOpenDF ( & reply . sfFile , fsRdWrPerm , & refNum ) ) ;
  129.     size = GetHandleSize ( foom ) ;
  130.     Error ( SetEOF ( refNum , size ) ) ;
  131.     HLock ( foom ) ;
  132.     Error ( FSWrite ( refNum , & size , * foom ) ) ;
  133.     Error ( FSClose ( refNum ) ) ;
  134.     Error ( FlushVol ( NULL , reply . sfFile . vRefNum ) ) ;
  135. }
  136.  
  137.